package com.mounting.wechat.common.util;

import com.mounting.wechat.common.message.MessageEnum;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * 返回数据
 *
 * @author Mark sunlightcs@gmail.com
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class Result<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    private Integer errcode;

    private String errmsg ;

    private T data;

    public static Result error() {
        return error(MessageEnum.SERVER_FAIL);
    }


    public static Result error(MessageEnum messageEnum,Object data){
        return Result.builder()
                .errcode(messageEnum.getCode())
                .errmsg(messageEnum.getMessage())
                .data(data)
                .build();
    }

    public static Result error(Object data){
        return Result.builder()
                .errcode(MessageEnum.SERVER_FAIL.getCode())
                .errmsg(MessageEnum.SERVER_FAIL.getMessage())
                .data(data)
                .build();
    }

    public static Result error(MessageEnum messageEnum){
        return Result.builder()
                .errcode(messageEnum.getCode())
                .errmsg(messageEnum.getMessage())
                .build();
    }


    public static Result ok(Object data) {
        return Result.builder()
                .errcode(MessageEnum.SERVER_SUCCESS.getCode())
                .errmsg(MessageEnum.SERVER_SUCCESS.getMessage())
                .data(data).build();
    }


    public static Result ok() {
        return Result.builder()
                .errcode(MessageEnum.SERVER_SUCCESS.getCode())
                .errmsg(MessageEnum.SERVER_SUCCESS.getMessage())
                .data(MessageEnum.SERVER_SUCCESS.getMessage())
                .build();
    }

}